package com.ruoyi.quartz.task;


import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.framework.config.ThreadExecutorPoolConfig;
import com.ruoyi.quartz.service.impl.TaskService;
import com.ruoyi.system.V2.inter.mapper.SelectPushMapper;
import com.ruoyi.system.model.domain.SelectPush;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import javax.annotation.Resource;
import java.util.List;


//@Configuration      //1.主要用于标记配置类，兼备Component的效果。
//@EnableScheduling
@Slf4j
public class AddTestTask {

    @Autowired
    private TaskService taskService;
    @Resource
    private SelectPushMapper selectPushMapper;

    //添加定时任务
    //标签同步
    private void synchronousLable() {
        log.info("标签同步接口");
        taskService.synchronousLable();
    }

//    @Scheduled(cron = "0 0/1 * * * ?")
    @Scheduled(cron = "0/5 * * * * ?")
    public void selectPushTask() throws InterruptedException {
        SelectPush selectPush = new SelectPush();
        selectPush.setState("0");
        selectPush.setType("5000");
        List<SelectPush> selectPushes = selectPushMapper.selectSelectPushList(selectPush);
//        for (SelectPush push : selectPushes) {
//            taskService.selectPush(10, push, "JYM");
//        }
        excuteTask(selectPushes);
    }

    private void excuteTask(List<SelectPush> selectPushes) {
        for (SelectPush selectPush : selectPushes) {
            taskService.selectPush(10, selectPush);
        }
    }

//
//    @Scheduled(cron = "0/2 * * * * ?")
//    public void selecttest() throws InterruptedException {
//
//        System.out.println("Scheduled1");
//        Thread.sleep(5000);
//    }
//
//    @Scheduled(cron = "0/2 * * * * ?")
//    public void selecttest1() throws InterruptedException {
//
//        System.out.println("Scheduled2");
//        Thread.sleep(2000l);
//    }



}
